// 获取项目根路径
function getWeiContextPath() {
    // return "http://localhost:8080/yyIntegral";  // 本地开发
    //return "https://do.anssy.com/yyIntegral";  //
    return "https://wx.youyoujifen.com/yyIntegral";  //客户域名
}

function getWeixinConfig() {
    var map = {
        APPID:"wx7a2b2f5b0dc0b9e1"
        // APPID: "wx76823dfb05c50794"
    }
    return map;
}

/*获取用户信息*/
function getUserInfo(userId) {
    var userInfo;
    if (userId == 0) {
        return userInfo;
    }
    $.ajax({
        type: "POST",
        cache: false,
        data: {userId: userId},
        async: false,
        url: getWeiContextPath() + "/wx/VipUser/queryUser",
        success: function (result) {
            userInfo = result.data
        }
    });
    return userInfo;
}

//返回图片路径
function getImgSrc(imgSrc) {
    return getWeiContextPath() + imgSrc;
}

//同步ajax,供方法中调接口
function tongBuAjax(params, url) {
    var data;
    $.ajax({
        type: "POST",
        cache: false,
        data: params,
        async: false,
        url: url,
        beforeSend: function (request) {
            request.setRequestHeader("X-Nideshop-Token", u.getStorage("userToken"))
        },
        success: function (result) {
            if (result.code == 401) {
                //请先登录……
                ue.clearStorage();
                $(location).attr("href", "../index.html?infrom=2");
            } else if (result.code == 1) {
                //调用失败
                data = "";
            } else {
                data = result.data;
            }
        },
        error: function (data) {
            data = "";
        }
    });
    return data;
}

//异步ajax,供全局调方法使用
function yiBuAjax(data, url, callback) {
    $.ajax({
        type: "POST",
        cache: false,
        data: data,
        url: url,
        beforeSend: function (request) {
            request.setRequestHeader("X-Nideshop-Token", u.getStorage("userToken"))
        },
        success: callback,
        error: function (data) {
            console.log(data.msg)
        }
    });
}


//获取页面请求路径中的参数
function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++) {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

// 从url 截取数据
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
    var context = "";
    if (r != null)
        context = r[2];
    reg = null;
    r = null;
    return context == null || context == "" || context == "undefined" ? "" : context;
}

//移除指定索引的对象
Array.prototype.remove = function (dx) {
    if (isNaN(dx) || dx > this.length) {
        return false;
    }
    for (var i = 0, n = 0; i < this.length; i++) {
        if (this[i] != this[dx]) {
            this[n++] = this[i]
        }
    }
    this.length -= 1
}

document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
    // 通过下面这个API隐藏右上角按钮
    WeixinJSBridge.call('hideOptionMenu');
    //隐藏导航键
    WeixinJSBridge.call('hideToolbar');
});

window.addEventListener("pageshow", function (e) {
    if (WeixinJSBridge) {
        // 通过下面这个API隐藏右上角按钮
        WeixinJSBridge.call('hideOptionMenu');
    }
});

$(function () {
    $('body').append('<div class="scan-code"></div>\n' +
        '    <div class="scan-model">\n' +
        '        <div class="scan-content">\n' +
        '            <img src="'+getWeiContextPath()+'/wxMoudle/images/gzhImg.jpg" alt="">\n' +
        '            <div class="scantitle">关注公众号查看积分详情</div>\n' +
        '            <div>\n' +
        '                使用说明: <br>\n' +
        '                <div style="text-indent: 2em;">\n' +
        '                到合作商家消费，结账时直接扫商家“有有积分”收款二维码进行付款；或者从“有有积分”公众号里找到当前消费的商家，进入店铺详情页面，点击右下角“去支付”按钮进行付款，付款后就可以获得积分，积分可以兑换成零钱，并且可以提现。</div>\n' +
        '            </div>\n' +
        '        </div>\n' +
        '    </div>')

    $('body').append('<style>.scan-code{position: fixed;right: 0;top:44%;background:rgba(0,0,0,0.2) url("'+getWeiContextPath()+'/wxMoudle/images/ewm3.png") no-repeat center center;background-size: 30px 30px;\n' +
        '    width: 30px;height: 30px;border-radius: 5px 0 0 5px; padding:0 0 0 5px;}\n' +
        '.scan-model{position: fixed;top:0;left:0;width: 100%;height: 100%; display:none;background-color: rgba(0, 0, 0, 0.5);z-index: 100; }\n' +
        '.scan-model img{width: 200px;height: 200px;display: block;margin:0 auto}\n' +
        '.scan-model .scantitle{font-weight: bold;font-size: 14px;color:#000;text-align: center;}\n' +
        '.scan-content{position: fixed;top:50%;left:50%;transform: translate(-50%,-50%);padding:15px 30px;width: 90%;box-sizing: border-box; background-color: #fff;border-radius: 8px;font-size: 14px;color: #333;}</style>')

    $('.scan-code').click(function () {
        $('.scan-model').show()
    })
    $('.scan-model').click(function () {
        $('.scan-model').hide()
    })
})



